﻿using MachineVision.Views;
using MachineVision.Services;
using Prism.DryIoc;
using Prism.Ioc;
using System.Windows;
using MachineVision.ViewsModels;
using Prism.Regions;
using Prism.Modularity;
using MachineVision.TemplateMatch;
using MachineVision.Shared.Services;
using MachineVision.Core.TemplateMatch;
using MachineVision.Core.TemplateMatch.NccModel;
using MachineVision.Core.OCR;

namespace MachineVision
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : PrismApplication
    {
        protected override Window CreateShell() => null;

        protected override void OnInitialized()
        {
            var container = ContainerLocator.Container;
            var shell = container.Resolve<Object>("MainView");
            if(shell is Window view)
            {
                var regionManager = container.Resolve<IRegionManager>();
                RegionManager.SetRegionManager(view, regionManager);
                RegionManager.UpdateRegions();

                if (view.DataContext is INavigationAware navigationAware)
                {
                    navigationAware.OnNavigatedTo(null);
                    App.Current.MainWindow = view;
                }
            }
            base.OnInitialized();
        }

        protected override void RegisterTypes(IContainerRegistry service)
        {
            //系统设置服务
            service.Register<ISettingService, SettingService>();

            //系统模块
            service.RegisterForNavigation<SettingView, SettingViewModel>();
            service.RegisterForNavigation<MainView, MainViewModel>();
            service.RegisterForNavigation<DashboardView, DashboardViewModel>();
            service.RegisterSingleton<INavigationMenuService, NavigationMenuService>();

            //模版匹配服务
            service.Register<ITemplateMatchService, ShapeModelService>(nameof(TempalteMatchType.ShapeModel));
            service.Register<ITemplateMatchService, NccModelService>(nameof(TempalteMatchType.NccModel));

            service.Register<BarCodeService>();
            service.Register<QrCodeService>();
        }

        protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
        {
            moduleCatalog.AddModule<TemplateMatchModule>();
            base.ConfigureModuleCatalog(moduleCatalog);
        }
    }

}
